#include "AttributeAdder.h"
#include "..\core\src\AssetManager.h"
#include "AssetPool.h"
#include "../core/src/container/Attribute.h"

namespace Xps
{
	AttributeAdder::AttributeAdder(QWidget* parent) : AssetAdder(parent, "Add Attribute", ":/rs/images/attribute.png")
	{
		//head = setupHeader("Add Question2", );
		content = setupContent();
	}

	AttributeAdder::~AttributeAdder(void)
	{
	}


	QWidget* AttributeAdder::setupContent()
	{	
		text = new QLineEdit();
		QGridLayout* content_layout = new QGridLayout();
		content->setLayout(content_layout);
		content_layout->addWidget(text, 1, 0, Qt::AlignTop);
		content_layout->addWidget(new QLabel("Enter the name of the attribute you would like to create."),0, 0, Qt::AlignBottom);
		text->setFocus(Qt::FocusReason::TabFocusReason);

		return content;
	}

	void AttributeAdder::accept()
	{
		XpsAssets::AssetManager* am = ((Xps::AssetPool*) parent())->am;
		int id = am->createAttribute();
		XpsAssets::Attribute* a = am->getAttribute(id);
		a->setName(text->text());
		QDialog::accept();
	}
}